Skip to content

ref(analytics): Transform analytics events for TET-827 #95207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

constantinius
Copy link
Contributor

  • Transform event classes to use @analytics.eventclass decorator
  • Transform analytics.record calls to use event class instances
  • Update imports as needed

Closes TET-827

- Transform event classes to use @analytics.eventclass decorator
- Transform analytics.record calls to use event class instances
- Update imports as needed

Closes TET-827
@constantinius constantinius requested review from a team as code owners July 10, 2025 09:13
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 10, 2025
cursor[bot]

This comment was marked as outdated.

Copy link

codecov bot commented Jul 10, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
27218 2 27216 243
View the top 2 failed test(s) by shortest run time
tests.sentry.api.helpers.test_group_index.ValidateSearchFilterPermissionsTest::test_negative
Stack Traces | 1.28s run time
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:64: in test_negative
    self.assert_analytics_recorded(mock_record)
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:47: in assert_analytics_recorded
    mock_record.assert_called_with(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:977: in assert_called_with
    raise AssertionError(_error_message()) from cause
#x1B[1m#x1B[31mE   AssertionError: expected call not found.#x1B[0m
#x1B[1m#x1B[31mE   Expected: record('advanced_search.feature_gated', user_id=210, default_user_id=210, organization_id=4556398608973824)#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(AdvancedSearchFeatureGateEvent(uuid_=UUID('dd678f3e-5e69-11f0-b894-00224823d8ed'), datetime_=datetime.datetime(2025, 7, 11, 15, 15, 23, 786874, tzinfo=datetime.timezone.utc), user_id='210', default_user_id='210', organization_id='4556398608973824'))#x1B[0m
tests.sentry.api.helpers.test_group_index.ValidateSearchFilterPermissionsTest::test_wildcard
Stack Traces | 1.32s run time
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:86: in test_wildcard
    self.assert_analytics_recorded(mock_record)
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:47: in assert_analytics_recorded
    mock_record.assert_called_with(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:977: in assert_called_with
    raise AssertionError(_error_message()) from cause
#x1B[1m#x1B[31mE   AssertionError: expected call not found.#x1B[0m
#x1B[1m#x1B[31mE   Expected: record('advanced_search.feature_gated', user_id=257, default_user_id=257, organization_id=4556398611857408)#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(AdvancedSearchFeatureGateEvent(uuid_=UUID('f77b8b8c-5e69-11f0-b894-000d3a352aa2'), datetime_=datetime.datetime(2025, 7, 11, 15, 16, 7, 665572, tzinfo=datetime.timezone.utc), user_id='257', default_user_id='257', organization_id='4556398611857408'))#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing User ID in Integration Comments Sync Event

The IntegrationIssueCommentsSyncedEvent analytics call in src/sentry/integrations/tasks/create_comment.py and src/sentry/integrations/tasks/update_comment.py no longer captures the user_id parameter. This is because the user_id field was removed from the IntegrationIssueCommentsSyncedEvent class, leading to a loss of user tracking data that was previously captured and may impact downstream analytics consumers.

src/sentry/integrations/tasks/create_comment.py#L70-L77

note.save()
analytics.record(
IntegrationIssueCommentsSyncedEvent(
provider=installation.model.provider,
id=installation.model.id,
organization_id=external_issue.organization_id,
)
)

src/sentry/integrations/tasks/update_comment.py#L70-L77

installation.update_comment(external_issue.key, user_id, note)
analytics.record(
IntegrationIssueCommentsSyncedEvent(
provider=installation.model.provider,
id=installation.model.id,
organization_id=external_issue.organization_id,
)
)

Fix in CursorFix in Web


Bug: Event ID Type Mismatch Causes Serialization Errors

The id field in IntegrationResolvePREvent is incorrectly typed as str. It should be int to match the repo.integration_id value passed to it, which is an integer database ID. This also creates an inconsistency with IntegrationResolveCommitEvent.id, which is correctly typed as int and uses the same value. This type mismatch can lead to runtime errors or data serialization issues.

src/sentry/integrations/analytics.py#L74-L79

@analytics.eventclass("integration.resolve.pr")
class IntegrationResolvePREvent(analytics.Event):
provider: str | None
id: str
organization_id: str

Fix in CursorFix in Web


Bug: Type Mismatch in Analytics Event IDs

Analytics event classes define organization_id, project_id, and group_id as str. However, these fields are consistently populated with integer IDs from model objects (e.g., project.id, group.id), leading to type mismatches and errors.

src/sentry/analytics/events/first_new_feedback_sent.py#L5-L7

class FirstNewFeedbackSentEvent(analytics.Event):
organization_id: str
project_id: str

src/sentry/analytics/events/first_sourcemaps_sent.py#L6-L11

user_id: int
organization_id: str
project_id: str
platform: str | None = None
url: str | None = None
project_platform: str | None = None

src/sentry/analytics/events/issue_deleted.py#L5-L11

class IssueDeletedEvent(analytics.Event):
group_id: str
delete_type: str
organization_id: str
project_id: str
user_id: str | None = None
default_user_id: str

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant